
import ddf.minim.*;
import java.util.ArrayList;
import processing.core.*;


public class Jeu extends PApplet
{
    Player player;
    Timer2 timer2;
    AudioSample ping;
    Minim minim;
    
    Base base;
    Raffinerie raffinerie;
    Caserne caserne;
    Usine usine;
    Spatioport spatioport;
    
    BunkerAlly bunkerAlly;
    BunkerEnemy bunkerEnemy;
            
    //ArrayList<ImageBarProcess> tabProcessBar;
    ArrayList<Soldier> tabSoldier = new ArrayList<Soldier>();
    
    int buildingSet;
    PImage screenHud;
    
    //////////////////////////////////////////////////////////a voir
    
    String productionBatiment = "ImageHub/crystal.png";
    String ressource_crystal = ""+0+"";
    String ressource_gas = ""+200+"";
    
    boolean debut_gas = false;
    //////////////////////////////////////////////////////////
    
    public static void main(String[] args)
    {
        PApplet.main(new String[]{"Jeu"});    
    }
    
    @Override
    public void setup() 
    {
        // Taille de l'ecran 
        size(1253,690);
        textSize(14);
        
        //Soldier soldier = new Soldier(this,);
        player = new Player(this);
        // Lancement du timer 
        timer2 = new Timer2(this);
        
        // Creation des batiments
        base = new Base(this);
        raffinerie = new Raffinerie(this);
        caserne = new Caserne(this);
        usine = new Usine(this);
        spatioport = new Spatioport(this);
        
        bunkerAlly = new BunkerAlly(this);
        bunkerEnemy = new BunkerEnemy(this);
        
        
        minim = new Minim(this);
        ping = minim.loadSample("connected.wav");
        ping.trigger();
    }
    
    public void draw()
    {
        background(0);
        
        // Affichage de l'arriere plan
        PImage background = loadImage("background.png");
        image(background ,0 ,0 ,1253 ,657);
        PImage hud = loadImage("hud_1300.png");
        image(hud ,0 ,530 ,1300 ,160);
        
        
        PImage bunker_terran = loadImage("bunker_terran.png");
        PImage base_ennemy = loadImage("base_ennemy.png");

        
        // On place les Objet avec leurs Image et coordonées
        base.display();
        raffinerie.display();
        caserne.display();
        usine.display();
        spatioport.display();
        bunkerAlly.display();
        bunkerEnemy.display();
        
        
        // On Affiche le ProcessBar du batiment selectionné
        
        if(buildingSet != 0)
        {
            switch (buildingSet)
            {
                case 1:
                    base.displayProcessBar();
                    break;
                case 2:
                    raffinerie.displayProcessBar();
                    break;
                case 3:
                    caserne.displayProcessBar();
                    break;
                case 4:
                    usine.displayProcessBar();
                    break;
                case 5:
                    spatioport.displayProcessBar();
                    break;
                default:
                    break;
            }
        }
        
        /////////////////////////////////////////////
        // une foi les process fini on affiche tout ce qui manque
        /////////////////////////////////////////////
        if(screenHud != null)
        {
            image(screenHud,50,590,75,75);
        }
        
        
        
        timer2.displayTime();
        
        if( timer2.getTimeForUpRessource())
        {
            player.upRessources();
        }
        player.displayRessources();
        
        /*
        if(tabProcessBar != null)
        {
            for (ImageBarProcess theBase : tabProcessBar)
            {
                image(theBase.getLogo(),theBase.getX(),theBase.getY(),theBase.getWidth(),theBase.getHeight());
            } 
        }
        * 
        */
        
        if(tabSoldier != null)
        {
            for (Soldier thesoldier : tabSoldier)
            {
                thesoldier.move();
                thesoldier.create();
            } 
        }
        
    }
    
    
    
    
// Lors du clique de la souris    
    public void mousePressed() 
    {

        //BASE
        if(base.onPosition(mouseX,mouseY))
        {
            buildingSet = 1;                                    /// On specifie le batiment séléctionné
            screenHud = base.getImage();
            //tabProcessBar = base.getProcessBar();
        }
        
        //RAFFINERIE
        if(raffinerie.onPosition(mouseX,mouseY))
        {
            buildingSet = 2;                                    /// On specifie le batiment séléctionné
            screenHud = raffinerie.getImage();
            //tabProcessBar = raffinerie.getProcessBar();
        }
        
        //CASERNE
        if(caserne.onPosition(mouseX,mouseY))
        {
            buildingSet = 3;                                     /// On specifie le batiment séléctionné
            screenHud = caserne.getImage();
            //tabProcessBar = caserne.getProcessBar();
            
            ping = minim.loadSample("caserne.wav");
            ping.trigger();
        }
        
        //USINE
        if(usine.onPosition(mouseX,mouseY))
        {
            buildingSet = 4;                                    /// On specifie le batiment séléctionné
            screenHud = usine.getImage();
            //tabProcessBar = usine.getProcessBar();
            
            ping = minim.loadSample("tank.wav");
            ping.trigger();
        }
        
        //SPATIOPORT
        if(spatioport.onPosition(mouseX,mouseY))
        {
            buildingSet = 5;                                    /// On specifie le batiment séléctionné
            screenHud = spatioport.getImage();                  /// On specifie l'image du batiment séléctionné
            //tabProcessBar = spatioport.getProcessBar();         /// On affiche les posibilité de selection
            
            ping = minim.loadSample("cuirasse.wav");
            ping.trigger();
        }
        
        
        
        
        // 1:BASE  2:CASERNE  3:RAFFINERIE  4:USINE  5:SPATIOPORT
        //PRODUIRE
        switch (buildingSet)
        {
            case 1:
                if(base.process(mouseX,mouseY))
                {
                    PImage marine = loadImage("marine.gif");
                    tabSoldier.add(new Soldier(marine,this));
                }
                
                break;
            case 2:
                raffinerie.process(mouseX,mouseY);
                break;
            case 3:
                caserne.process(mouseX,mouseY);
                break;
            case 4:
                usine.process(mouseX,mouseY);
                break;
            case 5:
                spatioport.process(mouseX,mouseY);
                break;
            default:
                break;
        }
         
    }
    
    public void stop() 
    {
        ping.close();
        minim.stop();
        super.stop();
    }
}

